package com.expmanage.actions.login;

import java.util.Map;

import com.opensymphony.xwork2.*;

@SuppressWarnings("serial")
public class sloginaction extends ActionSupport{
	private String username = "";
	private String password = "";
	private String image = "";

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public String execute() {
		String str = "failed";
		System.out.println("image:" + image);
		ActionContext context = ActionContext.getContext();
		@SuppressWarnings("rawtypes")
		Map session = context.getSession();
		String rand = (String) session.get("rand");
		System.out.println("rand:" + rand);
		if (image.equals(rand)) {
			System.out.println("success");
			sDataObject conn;
			try {
				conn = new sDataObject();

				if (conn.checkUser(this.username.trim(), this.password.trim())) {
					str = "success";
					Map<String, Object> se = ActionContext.getContext().getSession();
					se.put("user", this.getUsername());
					se.put("sid", new Integer(conn.getLogin_student().getSid()));
					se.put("role", "student");
				} else {
					str = "failed";
				}
			} catch (Exception e) {
				e.printStackTrace();
			}

			return str;
		} else
			return str;
	}

}
